package com.carlinfo.usercenter.servlet.back;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.carlinfo.usercenter.common.servlet.BaseServlet;
import com.carlinfo.userscenter.users.service.IAuthService;
import com.carlinfo.userscenter.users.service.impl.AuthServiceImpl;

public class AuthBackServlet extends BaseServlet
{
	/* 菜单服务类 */
	private IAuthService authService = new AuthServiceImpl();
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String method = request.getParameter("method");
		if("menuTreeList".equalsIgnoreCase(method))
		{
			menuTreeList(request,response);
		}
	}

	/**
	 * 树形结构
	 * @param request
	 * @param response
	 * @throws IOException 
	 * @throws ServletException 
	 */
	private void menuTreeList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		/*
		 * 从页面上接收参数角色id
		 * 由于是在Servlet,可以大方的写java代码
		 * 需要通过roleId和menuId判断是否选择,是否有权限
		 */
		//String roleId = request.getParameter("roleId");
		/* 调用service.jsp页面所需要的数据,service提供 */
		JSONArray resultArr = this.authService.findChildTreeMenuJSONService("");
		request.setAttribute("resultArr", resultArr.toJSONString());
		String path = "/WEB-INF/jsp/back/auth/menuTreeList.jsp" ; 
		/* 服务器跳转 */
		request.getRequestDispatcher(path).forward(request, response);
	}
}
